package com.example.cdctest.service.impl;

import com.example.cdctest.mapper.NoticeMapper;
import com.example.cdctest.pojo.Admin;
import com.example.cdctest.pojo.Notice;
import com.example.cdctest.service.NoticeService;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
@Transactional(rollbackFor = Exception.class)
public class NoticeServiceImpl implements NoticeService {

    @Resource
    private NoticeMapper noticeMapper;

    @Override
    public void insert(Notice object) {

    }

    //删除公告信息
    @Override
    public void delete(Integer id) {
        Notice notice=new Notice();
        notice.setId(id);
        noticeMapper.updateNoticeEnable(notice);
    }

    @Override
    public void delete(String ids) {

    }

    //修改公告信息的排序
    @Override
    public void update(Notice object) {
        noticeMapper.updateByPrimaryKey(object);
    }

    //根据公告信息的Id,查出该Id下的公告信息
    @Override
    public Notice findById(Integer id) {
        return noticeMapper.selectByPrimaryKey(id);
    }

    //取出所有未删除的公告信息
    @Override
    public List<Notice> findAll() {
        return noticeMapper.selectAllNotice();
    }

    @Override
    public PageInfo<Notice> findPage(int pageSize) {
        return null;
    }

    //根据公告信息的标题,公告信息的封面,具体的公告信息添加公告
    @Override
    public void insertNoticeMessage(String title, String content, String image, Admin admin) {
        Notice notice=new Notice();
        notice.setPicture(image);
        notice.setContent(content);
        notice.setTitle(title);
        notice.setAdmin(admin);
        noticeMapper.insertSelective(notice);
    }

    //前台首页请求，取出后台配置数量的公告信息
    @Override
    public List<Notice> findAllServicesNotice(Integer noticeCount) {
        return noticeMapper.selectAllServicesNotice(noticeCount);
    }
}
